package org.example.service;


import lombok.extern.slf4j.Slf4j;
import org.example.mapper.NewsMapper;
import org.example.pojo.NewsCount;
import org.example.pojo.PeriodCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Component
@Slf4j
public class NewsService {
    @Autowired
    private NewsMapper newsMapper;

    public int getNewsNum(){
        return newsMapper.getNewsNum();
    }

    public Map<String, Object> getNewsList(){
        Map<String, Object> map = new HashMap<String, Object>();
        String[] names = new String[10];
        String[] counts = new String[10];
        List<NewsCount> list=newsMapper.getNewsList();
        int i = 0;
        for (NewsCount ns:list){
            String name = ns.getName();
            String count = ns.getCount()+"";
            names[i] = name;
            counts[i] = count;
            ++i;
        }
        map.put("name", names);
        map.put("count", counts);
        return map;
    }
    public Map<String, Object> getPeriodList(){
        Map<String, Object> map = new HashMap<String, Object>();
        String[] logtimes = new String[10];
        String[] counts = new String[10];
        List<PeriodCount> list = newsMapper.getPeriodList();
        int i = 0;
        for (PeriodCount pc:list){
            String logtime = pc.getLogtime();
            String count = pc.getCount()+"";
            logtimes[i] = logtime;
            counts[i] = count;
            ++i;
        }
        map.put("logtime", logtimes);
        map.put("count", counts);
        return map;
    }}

